<?php
    /**
    * Get list of meetings belongs to user
    */
    if (!defined('EXPONENT')) exit('');
    function _manage_meetings_return_empty()
    {
        $ret_object = null;
        $ret_object->total = 0;
        $ret_object->rows=array(); 
        echo json_encode($ret_object);
        return;
    }

    if (exponent_users_isAdmin() ||  exponent_permissions_check(array("administrate","meeting","meeting_delete","meeting_assistant"),exponent_core_makeLocation("profilemodule","_syscore","")))
    {  
        $id=0;
        if (isset($_REQUEST['id']))
            $id = intval($_REQUEST['id']);
        if ($id ==0)
            _manage_meetings_return_empty();
        else
        {
            // select user
            $sql_where="meeting_id = {$id}";
            if (isset($_REQUEST['search']))
            {
                $search = $_REQUEST['search'];
                $sql_where.=" AND action LIKE '%{$search}%'";
            }

            $page=1;
            if (isset($_REQUEST['page']))
                $page=intval($_REQUEST['page']);
            $pageSize=10;

            if (isset($_REQUEST['rows']))
                $pageSize=intval($_REQUEST['rows']);
            $start=($page-1)*$pageSize;

            // sort
            $sort="";
            if (isset($_REQUEST['sort'])){
                $sort = " ORDER BY {$_REQUEST['sort']} {$_REQUEST['order']}";
            }
            else{
                $sort = " ORDER BY date DESC";
            }

            $cuser = $db->selectObjects("profilemodule_meeting_history", "{$sql_where} {$sort} LIMIT {$start},{$pageSize}");
            if (!isset($cuser[0]->id))
            {
                _manage_meetings_return_empty();
            }
            else
            {
                foreach ($cuser as $k=>$v)
                {
                    $v->date = date('d/m/Y H:i:s',$v->date);                
                }
                $ret_object = null;
                $ret_object->total = $db->countObjects('profilemodule_meeting_history',"{$sql_where}");
                $ret_object->rows = $cuser; 
                echo json_encode($ret_object);
            }
        }
    }

?>